package com.altocloud.application;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import com.altocloud.database.DbUtil;
import com.altocloud.parse.Level2;

public class ApplicationLevel2 {

	File path;

	void iterateAllMesowestCSVFiles(String filePath) {
		File path = new File(filePath);
		setPath(path);
		int i = 0;
		File[] files = path.listFiles();
		while (i < files.length) {
			System.out.println("inside for loop");
			if (files[i].isFile()) { // this line weeds out other
										// directories/folders
				System.out.println("************" + files[i].toString()
						+ "**********");
				Level2 p = new Level2();
				p.parseCsvFile(files[i].toString());
			}
			i++;
		}
	}

	void iterateMesowestCSVFiles(int size, String filePath) {
		File path = new File(filePath);
		setPath(path);
		int i = 0;
		File[] files = path.listFiles();

		while (i < files.length && i < size) {
			System.out.println("inside for loop");
			if (files[i].isFile()) { // this line weeds out other
										// directories/folders
				System.out.println("************" + files[i].toString()
						+ "**********");
				Level2 p = new Level2();
				p.parseCsvFile(files[i].toString());
			}
			i++;
		}

	}

	void iterateAllWeatherFiles(String filePath) {
		File path = new File(filePath);
		setPath(path);
		int i = 0;
		File[] files = path.listFiles();
		while (i < files.length) {
			System.out.println("inside for loop");
			if (files[i].isFile()) { // this line weeds out other
										// directories/folders
				System.out.println("************" + files[i].toString()
						+ "**********");
				Level2 p = new Level2();
				try {
					p.parseOutFile(files[i].toString());
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			i++;
			System.out.println("NextFile");
		}
	}

	void iterateWeatherFiles(int size, String filePath) {
		File path = new File(filePath);
		setPath(path);
		int i = 0;
		File[] files = path.listFiles();
		while (i < files.length && i < size) {
			System.out.println("inside for loop");
			if (files[i].isFile()) { // this line weeds out other
										// directories/folders
				System.out.println("************" + files[i].toString()
						+ "**********");
				Level2 p = new Level2();
				try {
					p.parseOutFile(files[i].toString());
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			i++;
		}
	}

	public File getPath() {
		return path;
	}

	public void setPath(File path) {
		this.path = path;
	}

	public static void main(String[] args) {
		ApplicationLevel2 fi = new ApplicationLevel2();
		// To iterate over specified number of mesowest_csv.tbl files
		System.out.println("Execution Start");
		Long startTime = System.currentTimeMillis();

		// fi.iterateMesowestCSVFiles(1,"E:\\226data");

		// To iterate over ALL mesowest_csv.tbl files
		// fi.iterateAllMesowestCSVFiles("C:/jars/226Data/csv");

		// To iterate over specified number of mesowest.out file
		fi.iterateWeatherFiles(1, "E:\\226data");

		Long endTime = System.currentTimeMillis();
		Long timeTaken = endTime - startTime;
		System.out.println("Execution End");
		System.out.println("Time Taken is : " + timeTaken + " ms");

		// To iterate over ALL mesowest.out file
		// fi.iterateAllWeatherFiles("C:/jars/226Data/out");
	}

}
